package com.chuantou.yuba.util;

import android.app.Activity;
import android.graphics.Color;
import android.os.Parcel;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.KeyEvent;
import android.view.View;

public class ProfileSpan extends ClickableSpan {
	private long mUid;
	private String mName;
	private boolean mIsSelected = false;

	public ProfileSpan(Parcel src) {
		this.mUid = src.readLong();
		this.mName = src.readString();
	}

	public ProfileSpan(String name, long uid) {
		this.mUid = uid;
		this.mName = name;
	}

	@Override
	public void updateDrawState(TextPaint ds) {
		super.updateDrawState(ds);
		ds.setUnderlineText(false);
		ds.setColor(Color.parseColor("#047CD1"));
		if (mIsSelected) {
			ds.bgColor = Color.TRANSPARENT;
			mIsSelected = false;
		} else {
			ds.bgColor = Color.TRANSPARENT;
		}
	}

	public void onKeyAction(int action) {
		if (action == KeyEvent.ACTION_DOWN) {
			mIsSelected = true;
		} else {
			mIsSelected = false;
		}
	}

	public void writeToParcel(Parcel dest, int flags) {
		dest.writeLong(mUid);
		dest.writeString(mName);
	}

	@Override
	public void onClick(View widget) {
		Activity activity = StackManager.getCurrentActivity();
		if (activity != null) {
			ActivityHelper.toProfileActivity(activity, mUid);
		}
	}
}
